"""
# todo - add support for scheduling params?
try:
- # Initial domain create.
if 'image' not in self.info:
raise VmError('Missing image in configuration')
- self.image = ImageHandler.create(self, self.info['image'],
+ self.image = ImageHandler.create(self,
+ self.info['image'],
self.info['device'])
- log.debug('XendDomainInfo.construct: '
- 'calling initDomain(%s %s %s %s %s)',
- str(self.domid),
- str(self.info['memory_KiB']),
- str(self.info['ssidref']),
- str(self.info['cpu']),
- str(self.info['cpu_weight']))
-
- self.setDomid(self.image.initDomain(self.domid,
- self.info['memory_KiB'],
- self.info['ssidref'],
- self.info['cpu'],
- self.info['cpu_weight'],
- self.info['bootloader']))
-
- self.info['start_time'] = time.time()
-
- log.debug('init_domain> Created domain=%d name=%s memory=%d',
- self.domid, self.info['name'], self.info['memory_KiB'])
+ self.initDomain()
# Create domain devices.
self.construct_image()
self.destroy()
raise
+
+ def initDomain(self):
+ log.debug('XendDomainInfo.initDomain: %s %s %s %s)',
+ str(self.domid),
+ str(self.info['memory_KiB']),
+ str(self.info['ssidref']),
+ str(self.info['cpu_weight']))
+
+ self.domid = xc.domain_create(dom = self.domid or 0,
+ ssidref = self.info['ssidref'])
+ if self.domid <= 0:
+ raise VmError('Creating domain failed: name=%s' %
+ self.vm.getName())
+
+ if self.info['bootloader']:
+ self.image.handleBootloading()
+
+ xc.domain_setcpuweight(self.domid, self.info['cpu_weight'])
+ m = self.image.getDomainMemory(self.info['memory_KiB'])
+ xc.domain_setmaxmem(self.domid, m)
+ xc.domain_memory_increase_reservation(self.domid, m, 0, 0)
+
+ cpu = self.info['cpu']
+ if cpu is not None and cpu != -1:
+ xc.domain_pincpu(self.domid, 0, 1 << cpu)
+
+ self.info['start_time'] = time.time()
+
+ log.debug('init_domain> Created domain=%d name=%s memory=%d',
+ self.domid, self.info['name'], self.info['memory_KiB'])
+
+
def configure_vcpus(self, vcpus):
d = {}
for v in range(0, vcpus):
class ImageHandler:
"""Abstract base class for image handlers.
- initDomain() is called to initialise the domain memory and parse
- the configuration.
-
createImage() is called to configure and build the domain from its
kernel image and ramdisk etc.
("image/cmdline", self.cmdline),
("image/ramdisk", self.ramdisk))
+
+ def handleBootloading():
+ self.unlink(self.kernel)
+ self.unlink(self.ramdisk)
+
+
def unlink(self, f):
if not f: return
try:
except OSError, ex:
log.warning("error removing bootloader file '%s': %s", f, ex)
- def initDomain(self, dom, memory, ssidref, cpu, cpu_weight, bootloading):
- """Initial domain create.
-
- @param memory In KiB
- @return domain id
- """
-
- mem_kb = self.getDomainMemory(memory)
- dom = xc.domain_create(dom = dom or 0, ssidref = ssidref)
- # if bootloader, unlink here. But should go after buildDomain() ?
- if bootloading:
- self.unlink(self.kernel)
- self.unlink(self.ramdisk)
- if dom <= 0:
- raise VmError('Creating domain failed: name=%s' %
- self.vm.getName())
- if cpu is None:
- cpu = -1;
- log.debug("initDomain: cpu=%d mem_kb=%d ssidref=%d dom=%d", cpu, mem_kb, ssidref, dom)
- xc.domain_setcpuweight(dom, cpu_weight)
- xc.domain_setmaxmem(dom, mem_kb)
-
- try:
- xc.domain_memory_increase_reservation(dom, mem_kb, 0, 0)
- except:
- xc.domain_destroy(dom)
- raise
-
- if cpu != -1:
- xc.domain_pincpu(dom, 0, 1<<int(cpu))
- return dom
def createImage(self):
"""Entry point to create domain memory image.